package com.example.springdatajpaderivedquerymethod.repositories;

import com.example.springdatajpaderivedquerymethod.model.Employee;
import com.example.springdatajpaderivedquerymethod.model.Phone;
import com.example.springdatajpaderivedquerymethod.model.PhoneType;
import com.example.springdatajpaderivedquerymethod.model.Saler;
import org.springframework.data.jpa.domain.Specification;

import javax.persistence.criteria.*;
import java.util.ArrayList;
import java.util.List;

public class EmployeeSpecification {
    public static Specification<Employee> getEmployeeByNameSpec(String name){
        return (root, criteriaQuery, criteriaBuilder) -> {
            List<Predicate> predicates = new ArrayList<>();
            if (name != null) {
                predicates.add(criteriaBuilder.and(criteriaBuilder.equal(root.<String>get("name"),name)));
            }
            return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
        };
    }

    public static Specification<Employee> getEmployeeByPhoneTypeSpec(PhoneType phoneType){
        return null;
    }
}
